package com.ding.pda.controller;


import com.ding.pda.dto.AddDto;
import com.ding.pda.dto.UpdateDto;
import com.ding.pda.entity.Pda;
import com.ding.pda.service.IPdaService;
import com.hs.common.api.dto.ResultVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * pda 前端控制器
 * </p>
 *
 * @author Ding
 * @since 2022-07-21
 */
@Slf4j
@Api(tags = "pda手持设备模块")
@RestController
@RequestMapping("/pda")
public class PdaController {

    @Autowired
    private IPdaService pdaService;

    /**
     * 分页查询手持pda设备列表
     * @param current
     * @param size
     * @return
     */
    @GetMapping("/condition/{current}/{size}")
    @ApiOperation("分页查询手持pda设备列表")
    public ResultVo findPdaByPages(
            @PathVariable @ApiParam(name = "current", value = "当前页数") Integer current,
            @PathVariable @ApiParam(name = "size", value = "页面大小") Integer size){
        return pdaService.findPdaByPages(current,size);
    }

    /**
     * 新增手持pda设备
     * @param addDto pda设备信息
     * @return
     */
    @PostMapping("/addPda")
    @ApiOperation("新增手持pda设备")
    public ResultVo addPda(@RequestBody AddDto addDto ){

        return pdaService.addPda(addDto);
    }


    /**
     * 修改手持pda设备信息
     * @param updateDto pda设备信息
     * @return
     */
    @PutMapping("/updatePda")
    @ApiOperation("修改手持pda设备信息")

    public ResultVo updatePda(@RequestBody UpdateDto updateDto ){
        return pdaService.updatePda(updateDto);
    }

    /**
     * 删除手持pda设备信息
     * @param pdaId 手持pda设备id
     * @return
     */
    @DeleteMapping("/deletePda")
    @ApiOperation("删除手持pda设备信息")
    public ResultVo deletePda(
            @RequestParam ("pdaId")@ApiParam(name = "pdaId", value = "手持pda设备编号")Integer pdaId
    ){
        return pdaService.deletePda(pdaId);
    }


    @GetMapping("/unbindPda")
    @ApiOperation("查询未绑定巡检员的pda设备，限定条件：巡检员id")
    public ResultVo unbindPda(){
        return pdaService.unbindPda();
    }

    /**
     * 绑定巡检员id，修改手持pda设备状态信息
     * @param pdaId
     * @param patrollerId
     * @param status
     * @return
     */
    @PutMapping("/bindPda")
    @ApiOperation("绑定巡检员id，修改手持pda设备状态信息")
    public ResultVo bindPda(
            @RequestParam ("pdaId")@ApiParam(name = "pdaId", value = "手持pda设备编号")Long pdaId,
            @RequestParam ("patrollerId")@ApiParam(name = "patrollerId", value = "巡检员id")Long patrollerId,
            @RequestParam ("status")@ApiParam(name = "status", value = "pad状态")String status
    ){
        return pdaService.bindDevice(pdaId,patrollerId,status);
    }


}

